package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.E2R;
import com.sl.au.entity.EventType;
import com.sl.au.entity.M2R;
import com.sl.au.entity.Module;
import com.sl.au.entity.Role;

import java.util.List;

public interface E2RRepository extends JpaRepository<E2R, String> {
	//通过角色得到所有的m2r
	public Page<E2R> findByRole(Role role, Pageable pageable);

	// 得到配置了的模块数据条数
	@Query("select count(*) as num from E2R where role=?1")
	int getListNum(Role role);

	// 通过模块和角色得到M2R实体
	public E2R findByEventTypeAndRole(EventType eventType, Role role);
	
	// 获得role的所有菜单模块
	@Query("select m2.eventType from E2R m2 where m2.role=?1")
	List<EventType> findEventTypeByRole(Role role);
}
